package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.safe.domain.vo.BizEnterCheckProjectVO;
import com.ruoyi.safe.service.ICommonProjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.BizEnterCheckProject;
import com.ruoyi.safe.service.IBizEnterCheckProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业检查-项目Controller
 *
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/enterCheckProject/enterCheckProject")
public class BizEnterCheckProjectController extends BaseController
{
    @Autowired
    private IBizEnterCheckProjectService bizEnterCheckProjectService;
    @Autowired
    private ICommonProjectService commonProjectService;

    /**
     * 查询企业检查-项目列表
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizEnterCheckProject bizEnterCheckProject)
    {
        startPage();
        List<BizEnterCheckProjectVO> list = bizEnterCheckProjectService
                .selectBizEnterCheckProjectList(bizEnterCheckProject, SecurityUtils.getLoginUser().getUser());
        return getDataTable(list);
    }

    /**
     * 导出企业检查-项目列表
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:export')")
    @Log(title = "企业检查-项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizEnterCheckProject bizEnterCheckProject)
    {
        List<BizEnterCheckProjectVO> list = bizEnterCheckProjectService
                .selectBizEnterCheckProjectList(bizEnterCheckProject, SecurityUtils.getLoginUser().getUser());
        ExcelUtil<BizEnterCheckProjectVO> util = new ExcelUtil<>(BizEnterCheckProjectVO.class);
        util.exportExcel(response, list, "企业检查-项目数据");
    }

    /**
     * 获取企业检查-项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizEnterCheckProjectService.selectBizEnterCheckProjectById(id, SecurityUtils.getLoginUser().getUser()));
    }

    /**
     * 新增企业检查-项目
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:add')")
    @Log(title = "企业检查-项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizEnterCheckProject bizEnterCheckProject)
    {
        bizEnterCheckProjectService
                .insertBizEnterCheckProject(bizEnterCheckProject, SecurityUtils.getLoginUser().getUser());
        return success();
    }

    /**
     * 修改企业检查-项目
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:edit')")
    @Log(title = "企业检查-项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizEnterCheckProject bizEnterCheckProject)
    {
        return toAjax(bizEnterCheckProjectService
                .updateBizEnterCheckProject(bizEnterCheckProject, SecurityUtils.getLoginUser().getUser()));
    }

    /**
     * 删除企业检查-项目
     */
    @PreAuthorize("@ss.hasPermi('enterCheckProject:enterCheckProject:remove')")
    @Log(title = "企业检查-项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizEnterCheckProjectService.deleteBizEnterCheckProjectByIds(ids));
    }

}
